<?php

namespace app\base\command;


use app\base\model\AiVoice;
use app\base\model\RedianData;
use app\base\model\RedianTask;
use app\base\service\TaskService;
use app\base\service\XjyService;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
/**
 * 小甲鱼视频视频模板生成
 * Class SmsNum
 * @package app\common\command
 */
class CreateXjyVideoTemplate extends Command
{
    /**
     * 配置指令
     */
    protected function configure()
    {
        $this->setName('xbase:CreateXjyVideoTemplate');
        $this->setDescription('CreateXjyVideoTemplate');
    }

    protected function execute(Input $input, Output $output)
    {
        $queue_data = $this->queue->data;
        $id = $queue_data['id'];
        $list = $this->app->db->name("ai_voice")->whereIn('id',$id)->order('id','desc')->select()->toArray();
        $this->setQueueProgress("接收到id:{$id}");
        foreach ($list as $data){
            $this->setQueueProgress("正在处理:{$data['name']}");
            $r = XjyService::instance()->createAvatar($data['name'],$data['file_url']);
            $this->setQueueProgress("小甲鱼返回值".json_encode($r));
            if($r['code']==0){
                $this->setQueueProgress("{$data['name']}请求失败");
                $this->app->db->name("ai_voice")->where(['id'=>$data['id']])->update(['status'=>3,'error_msg'=>"生成失败,请稍后重试"]);
            }else{
                $this->app->db->name("ai_voice")->where(['id'=>$data['id']])->update(['code'=>$r['data']]);
            }

            // $data['code'] = $r['data'];

        }

       // $this->app->db->name("redian_push_schedule")->where(['task_id'=>$task_id])->update(['status'=>1]);
        $this->setQueueSuccess("任务完成");


    }




}
